﻿
function CenterItem(theItem) {
    var winWidth = $(window).width();
    var winHeight = $(window).height();
    var windowCenter = winWidth / 2;
    var itemCenter = $(theItem).width() / 2;
    var theCenter = windowCenter - itemCenter;
    var windowMiddle = winHeight / 2;
    var itemMiddle = $(theItem).height() / 2;
    var theMiddle = windowMiddle - itemMiddle;

    //xác định cho bên trái
    if (winWidth > $(theItem).width()) { //horizontal
        $(theItem).css('left', theCenter);
    } else {
        $(theItem).css('left', '0');
    }

    // xác định cho top
    /*if (winHeight > $(theItem).height()) { //vertical
    $(theItem).css('top', theMiddle);
    } else {
    $(theItem).css('top', '0');
    }*/
}
$(document).ready(function () {
    CenterItem('#Main');
});
$(window).resize(function () {
    CenterItem('#Main');
});


